--[[
Name: BrownieHelper
Developed by: Sonora (The Dragon Flight)
Website: http://sonora.kirintor.googlepages.com/contents
SVN: http://code.google.com/p/browniehelper/source/browse
License: GNU General Public License v3
]]

--[[
Collection of simple dialog boxes exposed with simple calls.

Plain simple.
]]


local __version__ = "1.0"

function messageDialog(message_text, close_callback)
    --[[
    Puts up a message dialog box with message_text.  Calls close_callback() when
    the dialog is closed via the single "OK" button.
    ]]--
    if close_callback==nil then close_callback = function() end end
    
    StaticPopupDialogs["utilityDialogs"..tostring(dialog_counter)] = {
        text = tostring(message_text),
        button1 = "Done",
        OnAccept = function() close_callback() end,
        timeout = 0,
        whileDead = 1,
        hideOnEscape = 1
    }
    
    StaticPopup_Show ("utilityDialogs"..tostring(dialog_counter))
    advCounter()
    
end

function yesnoDialog(message_text, response_callback)
    --[[
    Opens a message box with message_text and calls
    response_callback(true | false) based on whether yes or no was clicked by
    the user.
    ]]
    
    StaticPopupDialogs["utilityDialogs"..tostring(dialog_counter)] = {
        text = tostring(message_text),
        button1 = "Yes",
        button2 = "No",
        OnAccept = function() response_callback(true) end,
        OnCancel = function() response_callback(false) end,
        timeout = 0,
        whileDead = 1,
        hideOnEscape = 1
    }
    
    StaticPopup_Show ("utilityDialogs"..tostring(dialog_counter))
    advCounter()
    
end

function inputDialog(message_text, response_callback, default_text)
    --[[
    Opens a message box with message_text and a text input box and calls
    response_callback(text) with the input text when the user clicks the "OK"
    button.
    ]]--
    
    StaticPopupDialogs["utilityDialogs"..tostring(dialog_counter)] = {
        text = tostring(message_text),
        button1 = "Done",
        button2 = "Cancel",
        OnShow = function() getglobal(this:GetName().."EditBox"):SetText((default_text~=nil and tostring(default_text) or "")) end,
        OnAccept = function() response_callback(getglobal(this:GetParent():GetName().."EditBox"):GetText()) end,
        timeout = 0,
        hasEditBox = 1,
        whileDead = 1,
        hideOnEscape = 1
    }
    
    StaticPopup_Show ("utilityDialogs"..tostring(dialog_counter))
    advCounter()

end

dialog_counter = 0
function advCounter()
    --Yes, this is a dumb way to recycle frame names and avoid cruft, and could most certainly lead to ruin.
    --But I'm a warlock... I get a little excited by ruin.  (And I'm lazy.)
    if dialog_counter < 16 then dialog_counter = dialog_counter + 1
    else dialog_counter = 0
    end
end

